<?php
/**
 *   EntryModal - data.php
 *   Author: Juan Dapena Paz (juan@bittingbits.com)
 *   Copyright (C) 2010 Bitting Bits S.L.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

defined('_JEXEC') or die('Restricted access');

class ModalView
{
    function index()
    {
        $session = JFactory::getSession();
        /**
        * EXAMPLE QUERY TO DETECT HIGHLIGHTED NEWS
        *
        * select c.title, c.fulltext 
        * from jos_content c 
        * where id = any (
        *     select a.itemid 
        *     from jos_flexicontent_tags_item_relations a 
        *          inner join jos_flexicontent_tags b 
        *          on a.tid=b.id 
        *     where b.name="highlighted");*/

        $db = JFactory::getDBO();
        
        $query = 'SELECT c.title, c.introtext';
        $query .= ' FROM #__content c';
        $query .= ' WHERE id = ANY (';
        $query .= ' SELECT a.itemid';
        $query .= ' FROM #__flexicontent_tags_item_relations a';
        $query .= ' INNER JOIN #__flexicontent_tags b';
        $query .= ' ON a.tid=b.id';
        $query .= ' WHERE b.name="highlighted");';
        
        $db->setQuery($query);
        $result = $db->loadObjectList();
        
        echo '<div class="entrymodal"><h1>'.JText::_('HIGHLIGHTS').'</h1>';
        foreach ($result as $element) {
            echo '<div class="highlightednew">';
            echo '<h2>'; echo $element->title; echo '</h2>';
            echo '<div class="highlightedcontent">';
            echo $element->introtext;
            echo '</div>';
            echo '</div>';
        }
        echo '</div>';
        
    }
}
?>
